package logic

import (
	"context"
	"errors"
	"go.uber.org/zap"
	"order_srv/internal/dao"
	"order_srv/internal/svc"
	"order_srv/order"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateAfterSaleLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateAfterSaleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAfterSaleLogic {
	return &CreateAfterSaleLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateAfterSaleLogic) CreateAfterSale(in *order.CreateAfterSaleRequest) (*order.CreateAfterSaleResponse, error) {
	afterSale, err := dao.CreateAfterSale(in)
	if err != nil {
		pkg.Error("创建售后失败", zap.Error(err))
		return nil, errors.New("创建售后失败")
	}

	return &order.CreateAfterSaleResponse{
		Success:     true,
		AfterSaleId: int64(afterSale.Id),
		Message:     "售后创建成功",
	}, nil
}
